package com.edu.leetcode.dataStruct;

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;

/**
 * @作者 five-five
 * @创建时间 2021/6/10
 */
public class SimpleMap {
    public static void main(String[] args) {

    }

    /**
     * 两个map，判断两个map是否有相同的key，如果有，比较value是否相同，如果相同用个容器把相同的value和key装起来
     * 默认m1.size>m2.size
     * @return
     */
    public Map<String, String> getSameToMap(Map<String, String> m1, Map<String, String> m2) {
        Map<String, String> resultMap = new LinkedHashMap<>();
        Set<String> keySet1 = m1.keySet();
        Set<String> keySet2 = m2.keySet();
        for (String s : keySet1) {
            if (keySet2.contains(s) && (m1.get(s).equals(m2.get(s)))) {
                resultMap.put(s,m1.get(s));
            }
        }
        return resultMap;
    }
}
